#include<stdio.h>
int main()
{
    int x[200];
    //freopen("in.txt","r",stdin);
    int n;
    scanf("%d",&n);
    int count = 0;
    for(int i = 0; i < n; i++) scanf("%d",&x[i]);
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n-i-1; j++)
        {
            if(x[j] > x[j+1])
            {
                int temp = x[j];
                x[j] = x[j+1];
                x[j+1] = temp;
                count++;
            }
        }
    }
    for(int i = 0; i < n; i++) printf("%d ",x[i]);
    printf("\n%d",count);
}